<?php

namespace AppBundle\DataFixtures\ORM;

use AppBundle\Entity\City;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

/**
 * @see City
 * @author Vlad Riabchenko <vriabchenko@webnet.fr>
 */
class LoadCities extends AbstractFixture implements OrderedFixtureInterface
{
    public function load(ObjectManager $manager)
    {
        // Cities of IDF in France
        $franceIDF = $this->getReference('region_france_idf');

        $paris = (new City())
            ->setName('Paris')
            ->setRegion($franceIDF);
        $manager->persist($paris);

        $chaville = (new City())
            ->setName('Chaville')
            ->setRegion($franceIDF);
        $manager->persist($chaville);

        $sevres = (new City())
            ->setName('Sèvres')
            ->setRegion($franceIDF);
        $manager->persist($sevres);

        // Cities of HDF in France
        $franceHDF = $this->getReference('region_france_hdf');

        $lille = (new City())
            ->setName('Lille')
            ->setRegion($franceHDF);
        $manager->persist($lille);

        $amiens = (new City())
            ->setName('Amiens')
            ->setRegion($franceHDF);
        $manager->persist($amiens);

        // Cities of Normandie in France
        $franceNormandie = $this->getReference('region_france_normandie');

        $caen = (new City())
            ->setName('Caen')
            ->setRegion($franceNormandie);
        $manager->persist($caen);

        // Cities of Baden-Württemberg in Germany
        $germanyBadenWurttemberg = $this->getReference('region_germany_baden_wurttemberg');

        $stuttgart = (new City())
            ->setName('Stuttgart')
            ->setRegion($germanyBadenWurttemberg);
        $manager->persist($stuttgart);

        // Cities of Bavaria in Germany
        $germanyBavaria = $this->getReference('region_germany_bavaria');

        $munich = (new City())
            ->setName('Munich')
            ->setRegion($germanyBavaria);
        $manager->persist($munich);

        $nuremberg = (new City())
            ->setName('Nürnberg')
            ->setRegion($germanyBavaria);
        $manager->persist($nuremberg);

        $augsburg = (new City())
            ->setName('Augsburg')
            ->setRegion($germanyBavaria);
        $manager->persist($augsburg);

        $manager->flush();
    }

    public function getOrder()
    {
        return 3;
    }
}
